﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Text;
using JinianNet.JNCms.Data;

namespace JinianNet.JNCms.SQLiteDAL
{
    public class Region : BaseDAL, IRegion
    {
        public List<Models.Region> GetList(string parent)
        {
            List<Models.Region> list = new List<Models.Region>();
            using (IDataReader rd = Db.Helper.ExecuteReader(CommandType.Text, "select * from [JNCms_Region] where [ParentAreaCode]=@ID", new SQLiteParameter("@ID", parent)))
            {
                while (rd.Read())
                {
                    list.Add(Db.Entity.PopulateEntity<Models.Region>(rd));
                }
            }
            return list;
        }

        public Models.Region GetItem(string item)
        {
            using (IDataReader rd = Db.Helper.ExecuteReader(CommandType.Text, "select * from [JNCms_Region] where [AreaCode]=@ID limit 1", new SQLiteParameter("@ID", item)))
            {
                if (rd.Read())
                {
                    return Db.Entity.PopulateEntity<Models.Region>(rd);
                }
            }
            return null;
        }
    }
}
